'use strict';

//云函数：解密密语
const db = uniCloud.database();
const collection = db.collection('cryptolalia');

exports.main = async (event, context) => {

	// 1. 检查参数
	if (!event.ciphertext) {
		return {
			code: 0,
			msg: '请检查传参！'
		};
	}


	let res = await collection.where({
		ciphertext: event.ciphertext,
		password: event.password || ''
	}).get();


	//返回数据给客户端
	if (res && res.data && res.data[0]) {
		return {
			code: 1,
			msg: '查询成功',
			data: {
				message: res.data[0].message
			}
		};
	} else {
		return {
			code: 0,
			msg: '密码错误！'
		};
	}
};
